/** @brief File implementing the main window of the application.
 *
 * This file contains the implementation of the application main window.
 *
 * @file MainWindow.cpp
 * @author Johan "Solo" Luisier
 * @date 2013/04/08
 */
#include "MainWindow.hpp"
#include "ui_MainWindow.h"

#include "RuleManager.hpp"

#include <QtCore/QDebug>

MainWindow::MainWindow( QWidget* parent )
    : QMainWindow( parent )
    , Rules( 8u )
    , ui( new Ui::MainWindow )
    , RuleEditor( 0 )
{
    ui -> setupUi( this );

    connect( ui -> actionQuit, SIGNAL( triggered() ),
             this, SLOT( close() ) );

    connect( ui -> actionEditRule, SIGNAL( triggered() ),
             this, SLOT( showRuleEditor() ) );

    Rules.addBirthCondition( 2u );

    Rules.addSurvivalCondition( 2u );
    Rules.addSurvivalCondition( 3u );
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::showRuleEditor()
{
    delete RuleEditor;
    RuleEditor = new RuleManager( Rules, this );

    switch ( RuleEditor -> exec() )
    {
    case QDialog::Accepted:
        Rules = RuleEditor -> rules();
        break;
    case QDialog::Rejected:
        qDebug() << "Changes discarded";
        break;
    default:
        qWarning( "Unknown returned value" );
    }
}
